<template>
  <div class="login-container">
    <div class="login-bac">
      <div class="login-form-container">
        <div class="login">
          <div class="login-info">
            <p class="name">
              春风异彩商城后台系统
              <br>
              <span class="sub">春风行动，异彩纷呈</span>
            </p>
          </div>

        </div>
        <div class="login-form">
          <el-form ref="ruleForm" :model="loginForm" :rules="loginRules">
            <!--            <div>-->
            <el-form-item prop="username">
              <el-input v-model="loginForm.username" placeholder="Username" />
              <i class="el-icon-user" />
            </el-form-item>
            <!--            </div>-->
            <el-form-item prop="password">
              <el-input v-model="loginForm.password" placeholder="Password" show-password />
              <i class="el-icon-lock" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" :loading="loading" @click="adminLogin('ruleForm')">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="version">Version: 3.2.4</div>

      </div>
    </div>

  </div>
</template>
<script>
import { adminLogin } from '@/api/login'
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [{ required: true, message: '请输用户名', trigger: 'blur' }],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  watch: {
    // $route: {
    //   handler: function(route) {
    //     this.redirect = route.query && route.query.redirect
    //   },
    //   immediate: true
    // }
  },
  methods: {
    adminLogin(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          adminLogin(this.loginForm).then(response => {
            this.loading = false
            if (response.code === 'M5000') {
              this.$notify({
                title: '信息',
                message: response.msg,
                type: 'warning'
              })
              return false
            } else {
              sessionStorage.setItem('token', response.data)
              this.$router.push({ path: '/' })
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .login-container{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /*background-color: #4d4d4d;*/

    background-image: url("~@/assets/login/login_bg.jpg");
    background-size: cover;
    height: 100%;
    width: 100%;

    .login-bac{
      height: 100%;
      width: 100%;
      background-color: rgba(38, 50, 56, 0.6);
      .login-form-container{
        -webkit-box-shadow: 0 0 100px rgba(0,0,0,.08);
        box-shadow: 0 0 100px rgba(0,0,0,.08);
        height: 350px;
        left: 50%;
        margin: -175px 0 0 -180px;
        padding: 36px;
        position: fixed;
        top: 50%;
        width: 360px;
        border-radius: 8px;
        background-color: white;
        .login{
          /*position: absolute;*/
          /*width: 288px;*/
          .login-info{
            height: 64px;
            margin-bottom: 22px;
            text-align: center;
            .name{
              bottom: 14px;
              display: inline-block;
              font-size: 18px;
              line-height: 20px;
              position: relative;
              text-align: center;
              .sub{
                font-size: 12px;
              }
            }
          }
        }
        .login-form{
          div{
            /*margin-bottom: 10px;*/
            position: relative;
            /deep/ input{
              padding-left: 32px;
            }
            i{
              position: absolute;
              top: 10px;
              left: 10px;
              font-size: 18px;
            }
          }
          button{
            width: 100%;
          }
        }
        .version{
          color: #888;
          text-align: center;
          font-size: 12px;
        }
      }
    }

  }

</style>
